﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using Hotel.Classes.Helper;
using Hotel.Models.Entity;

namespace Hotel.Models.DataAccess
{
    public class DAHotelInformation
    {
        public static HotelInformation GetHotelInformation()
        {
            HotelInformation hotel = new HotelInformation();
            DataTable dt;
            using (DBManager dbManager = new DBManager("stp_Get_HotelInformation"))
            {
                dt = dbManager.GetDatatable();
            }
            hotel.Name = DataHelper.Get(dt.Rows[0], "Name");
            hotel.Abbreviated = DataHelper.Get(dt.Rows[0], "Abbreviated");
            hotel.Star = DataHelper.GetInt(dt.Rows[0], "Star");
            hotel.Address = DataHelper.Get(dt.Rows[0], "Address");
            hotel.Phone = DataHelper.Get(dt.Rows[0], "Phone");
            hotel.Fax = DataHelper.Get(dt.Rows[0], "Fax");
            hotel.Email = DataHelper.Get(dt.Rows[0], "Email");
            hotel.Website = DataHelper.Get(dt.Rows[0], "Website");
            hotel.Police = DataHelper.Get(dt.Rows[0], "Police");
            hotel.Location = DataHelper.Get(dt.Rows[0], "Location");
            hotel.Description = DataHelper.Get(dt.Rows[0], "Description");
            return hotel;
        }

        public static bool SaveHotelInformation(HotelInformation hotel)
        {
            using (DBManager dbManager = new DBManager("stp_Create_HotelInformation"))
            {
                try
                {
                    dbManager.Add("p_Name", hotel.Name);
                    dbManager.Add("p_Abbreviated", hotel.Abbreviated);
                    dbManager.Add("p_Star", hotel.Star);
                    dbManager.Add("p_Address", hotel.Address);
                    dbManager.Add("p_Phone", hotel.Phone);
                    dbManager.Add("p_Fax", hotel.Fax);
                    dbManager.Add("p_Email", hotel.Email);
                    dbManager.Add("p_Website", hotel.Website);
                    dbManager.Add("p_Police", hotel.Police);
                    dbManager.Add("p_Location", hotel.Location);
                    dbManager.Add("p_Description", hotel.Description);
                    dbManager.ExecuteNonQuery();
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }

            }
        }
    }
}